<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  <meta name="layout" content="main"/>
  <title>Edit Event</title>
</head>
<body>
<div class="body">
  <h1>Edit Event</h1>
  <g:if test="${flash.message}">
    <div class="message">${flash.message}</div>
  </g:if>
  <g:hasErrors bean="${eventInstance}">
    <div class="errors">
      <g:renderErrors bean="${eventInstance}" as="list"/>
    </div>
  </g:hasErrors>
  <g:form method="post">
    <input type="hidden" name="id" value="${eventInstance?.id}"/>
    <input type="hidden" name="version" value="${eventInstance?.version}"/>
    <div class="dialog">
      <table>
        <tbody>

        <tr class="prop">
          <td valign="top" class="name">
            <label for="name">Name:</label>
          </td>
          <td valign="top" class="value ${hasErrors(bean: eventInstance, field: 'name', 'errors')}">
    <input type="text" id="name" name="name" value="${fieldValue(bean: eventInstance, field: 'name')}"/>
    </td>
    </tr>

    <tr class="prop">
      <td valign="top" class="name">
        <label for="description">Description:</label>
      </td>
      <td valign="top" class="value ${hasErrors(bean: eventInstance, field: 'description', 'errors')}">
        <input type="text" id="description" name="description" value="${fieldValue(bean: eventInstance, field: 'description')}"/>
      </td>
    </tr>

    <tr class="prop">
      <td valign="top" class="name">
        <label for="startDate">Start Date:</label>
      </td>
      <td valign="top" class="value ${hasErrors(bean: eventInstance, field: 'startDate', 'errors')}">
        <g:datePicker name="startDate" value="${eventInstance?.startDate}"></g:datePicker>
      </td>
    </tr>

    <tr class="prop">
      <td valign="top" class="name">
        <label for="endDate">End Date:</label>
      </td>
      <td valign="top" class="value ${hasErrors(bean: eventInstance, field: 'endDate', 'errors')}">
        <g:datePicker name="endDate" value="${eventInstance?.endDate}"></g:datePicker>
      </td>
    </tr>

    <tr class="prop">
      <td valign="top" class="name">
        <label for="location">Location:</label>
      </td>
      <td valign="top" class="value ${hasErrors(bean: eventInstance, field: 'location', 'errors')}">
        <input type="text" id="location" name="location" value="${fieldValue(bean: eventInstance, field: 'location')}"/>
      </td>
    </tr>

    </table>
          </td>
        </tr>

        </tbody>
      </table>
    </div>
    <div class="buttons">
      <span class="button"><g:actionSubmit class="save" value="Update"/></span>
      <span class="button"><g:actionSubmit class="delete" onclick="return confirm('Are you sure?');" value="Delete"/></span>
      <span class="button"><g:actionSubmit class="add" action="createPosition" value="Add Position"/></span>
    </div>
  </g:form>

  <h1>Event Positions</h1>
  <table>
    <tbody>
    <tr class="prop">
      <div id="positionTableHeader">
        <g:render template="/common/positionTableHeader"/>
      </div>
    </tr>
    <g:each var="p" in="${eventInstance.positions}">
      <tr class="prop">
        <td valign="top" class="value">${p.name}</td>
        <td valign="top" class="value">${p.description}</td>
        <td valign="top" class="value">${p.location}</td>
        <td valign="top" class="value">${p.startDate}</td>
        <td valign="top" class="value">${p.endDate}</td>
        <td valign="top" align="right" class="value">${p.numberOfVolunteers}</td>
        <td valign="top" class="value">
          <ul>
            <g:each var="v" in="${p.volunteers}">
              <li><g:link controller="volunteer" action="show" id="${v.id}">${v?.encodeAsHTML()}</g:link></li>
            </g:each>
          </ul>
        </td>
        <td valign="top">
          <g:if test="${p.volunteers}">
            <g:link controller="eventPosition" action="delete" id="${p.id}" params="[eventId:eventInstance.id]" onclick="alert('You cannot remove a position if someone is currently signed up to volunteer for that position.'); return false;">Delete Position</g:link>
          </g:if>
          <g:else>
            <g:link controller="eventPosition" action="delete" id="${p.id}" params="[eventId:eventInstance.id]" onclick="return confirm('Are you sure?');">Delete Position</g:link>
          </g:else>
        </td>
        <td valign="top">
          <g:link controller="eventPosition" action="edit" id="${p.id}" params="[eventId:eventInstance.id]">Edit Position</g:link>
        </td>
      </tr>
    </g:each>
    </tbody>
  </table>

</div>
</body>
</html>
